#pragma once
#include "matrix.h"
#include "mapcell.h"

#define UP 0
#define RIGHT 1
#define DOWN 2
#define LEFT 3

typedef vector< vector<Pair_xy> > backmatrix;
typedef vector< vector<MapCell> > imatrix;
typedef vector<string> actionList;
typedef vector<Pair_xy> oList;

class Robot
{
protected:
	int face;//Huong mat cua robot
	Pair_xy pos;	
	MaTran sourceMap;//Doc tap tin va luu vao day
	backmatrix Pre;//Ma tran luu lai duong da di
	imatrix iMap;//Ban do do robot dung khi di chuyen
	oList OKList;
	vector<Pair_xy>::iterator iOKList;
	actionList history;
public:
	Robot(void);
	~Robot(void);
	void init(istream&);
	Pair_xy getPos();
	void readSourceMap();//Doc thong tin o dang dat chan
	int getFace();

	void movefw();
	void turn(int); 
	void turn(Pair_xy);
	void grab();
	void go();
	bool move();
	int checkimap();//-1 = die; 1 = gold end; 0: keep going

	bool isInOKList(Pair_xy);

	Pair_xy upcell();//Cell co vi tri tuong doi x so voi cell hien tai
	Pair_xy downcell();
	Pair_xy leftcell();
	Pair_xy rightcell();
	Pair_xy nwcell();
	Pair_xy necell();
	Pair_xy swcell();
	Pair_xy secell();

	Pair_xy nextcell();//Cell o truoc mat robot

	void clearNearPit();//Danh dau cac o lan can la khong co Pit
	void clearNearMummy();//Danh dau la cac o lan can khong co Mummy
	void clearDiaPit();//Kiem o cheo de danh dau cac o lan can la khong co Pit
	void clearDiaMummy();//Kiem o cheo de danh dau cac o lan can la khong co Mummy

	friend bool operator == (Pair_xy,Pair_xy);
};
